<template>
  <component v-if="AsyncComp" :is="AsyncComp"></component>
</template>

<script>
import {ref,defineAsyncComponent} from 'vue'
export default {
  setup(){
    let str = `
    ({
      data(){
        return {mydata: '被还原的数据'}
      }
    })
    `
    //关键步骤, runtimeCompiler:true 要在webpack中配置编译模板
    const AsyncComp = ref(null)
    AsyncComp.value = defineAsyncComponent(()=>{
      let obj = eval( str )
      console.log(1111,obj);
      let a = new Promise((resolve, reject) => {
        resolve({
          template: `<div>测试defineAsyncComponent------------{{mydata}}</div>`,
          data: obj.data
        })
      })
      return a
    })
    window.AsyncComp = AsyncComp.value
    return {
      AsyncComp
    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
